home *** CD-ROM | disk | FTP | other *** search
- /* PC98<->IBM ファイル転送 Copyright (c) E.Suto , 1992-1993 */
- /* 修正履歴 Ver 0.00 1992/06/22 試作品 */
- /* Ver 0.10 1992/06/23 近所公開版 */
- /* Ver 0.20 1992/06/26 簡易サーバーモード追加,共用ドライブ対応*/
- /* Ver 0.21 1992/06/28 リモートコマンド追加 */
- /* Ver 0.30 1992/06/30 TIMEOUT()改造,オプション統合,速度表示 */
- /* Ver 0.31 1992/07/03 簡易サーバーを出来るだけ止めないよう */
- /* Ver 0.32 1992/07/03 速度表示の0割り算ガード(超手抜き) */
- /* Ver 0.33 1992/07/06 . の消し方変更 */
- /* Ver 0.34 1992/07/10 受信ファイルがルートに行ってしまうバグ修正 */
- /* Ver 0.35 1992/11/17 RS232Cのバグ修正(98版のみ) */
- /* Ver 0.36 1992/11/17 ちょっと高速化(^^; */
- /* Ver 0.37 1992/11/18 タイマ値最適化 */
- /* Ver 0.38 1992/11/18 送信ファイル名バグ修正 */
- /* Ver 0.39 1992/11/18 サーバーバグ修正 */
- /* Ver 0.41 1993/02/04 inpのwaitを#defineに */
- /* Ver 0.42 1993/02/04 ソースをちょっと統合(^^; */
- /* Ver 1.00 1993/ 2/ 3 失敗時にタイムアウトしない */
- /* Ver 1.01 1993/ 2/ 4 コマンド受信処理でタイムアウトしない */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <dos.h>
- #include <io.h>
- #include <fcntl.h>
- #include <signal.h>
- #include <string.h>
- #include <time.h>
- #include <sys\timeb.h>
-
- #define BUFFSIZE 32767
-
- void copyright() ;
- int connect_r() ;
- int connect_s() ;
- void fp_command() ;
- void fp_file() ;
- void fp_send() ;
- void fp_server() ;
- void fp_receive0() ; /* (^^;;;; */
- void fp_receive() ;
- int receive( int , unsigned char * ) ;
- void rs_init() ;
- int send( int , unsigned char * ) ;
- void sig_out() ;
- void timeout() ;
- void timeset() ;
- void usage() ;
-
- static int mode ; /* 動作モード 0:S 1:R 2:サ 4:サR 5:コ */
- static unsigned char name[128] ; /* 操作ファイル名 */
- static unsigned char path[128] ; /* 送信先パス名 */
- static unsigned char command[128]; /* 送信コマンド */
- static unsigned char buffer[BUFFSIZE];/* バッファ */
- struct find_t f_name ; /* ワイルドカード展開データ */
- struct timeb time_1 ; /* 速度計算用タイマ値1 */
- struct timeb time_2 ; /* 速度計算用タイマ値2 */
- static long timeout1 ; /* タイムアウト値 */
- static int debug ; /* 詳細表示 */
-
- /*---------------------------------------------------------------------------*/
-
- /* 送信メイン処理 */
- void fp_send()
- {
- int len , loop , i , err ;
- unsigned long f_len ;
- unsigned char *c , *c2 ;
- unsigned char path_name[128] , full_name[128] ;
- FILE *file ;
- int handle ;
- unsigned long speed , f_len_b ;
-
- /* ファイル送信前フラグ送信(^^; */
- buffer[0] = 0x02 ;
- if( send( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( debug ) printf( "ファイル送信フラグ送信OK。\n" ) ;
-
- /* ファイル送信フラグ送信(^^; */
- buffer[0] = 0x00 ;
- if( send( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( debug ) printf( "ファイル送信フラグ送信OK。\n" ) ;
-
- /* 受信先パス名長送信 */
- len = strlen( path ) ;
- *buffer = (unsigned char)len ;
- if( send( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( debug ) printf( "受信先パス名長送信OK。\n" ) ;
-
- /* 受信先パス名送信 */
- if( len ) {
- if( send( len , path ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( debug ) printf( "受信先パス名送信OK。\n" ) ;
- }
-
- /* PATH名取り出し */
- strcpy( path_name , name ) ;
- if( ( c = strrchr( path_name , ':' ) ) == NULL ) {
- c = path_name ;
- }
- if( ( c2 = strrchr( c , '\\' ) ) == NULL ) {
- c2 = c ;
- }
- if( *c2 == ':' || *c2 == '\\' ) *(c2+1) = 0x00 ;
- else strcpy( path_name , "" ) ;
-
- /* ワイルドカード展開 */
- if( ( _dos_findfirst( name , _A_ARCH|_A_RDONLY , &f_name ) ) != 0 ) {
- printf( "送信出来るファイルがありません。\n" ) ;
- buffer[0] = 0x00 ;
- if( send( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( mode == 2 ) return ;
- rs_init() ;
- exit( -1 ) ;
- }
- /* 送るデータ有り */
- buffer[0] = 0xff ;
- if( send( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
-
- /* 送信処理ループ */
- if( mode != 2 ) printf( " ファイル名 : ファイル長\n" ) ;
- for( ; ; ) {
- ftime( &time_1 ) ;
- err = 0 ;
-
- /* ファイルの長さを調べる _dos_finedではDIETしてあるデータの長さが分からない */
- strcpy( full_name , path_name ) ;
- strcat( full_name , f_name.name ) ;
- if( ( handle = open( full_name , O_RDONLY|O_BINARY ) ) == EOF ) {
- printf( "送信ファイルのオープンに失敗しました(%s)。\n" ,
- full_name ) ;
- buffer[0] = 0x00 ;
- if( send( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( mode == 2 ) return ;
- rs_init() ;
- exit( -1 ) ;
- }
- f_len = filelength( handle ) ;
- f_len_b = f_len * 8l ;
- close( handle ) ;
-
- /* ファイルのオープン */
- if( ( file = fopen( full_name , "rb" ) ) == NULL ) {
- printf( "送信ファイルのオープンに失敗しました。\n" ) ;
- buffer[0] = 0x00 ;
- if( send( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( mode == 2 ) return ;
- rs_init() ;
- exit( -1 ) ;
- }
-
- /* 送信データのオープンOK */
- buffer[0] = 0xff ;
- if( send( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
-
- /* ファイル名長送信 */
- len = strlen( f_name.name ) ;
- *buffer = (unsigned char)len ;
- if( send( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( debug ) printf( "ファイル名長送信OK。\n" ) ;
-
- /* ファイル名送信 */
- strcpy( name , f_name.name ) ;
- if( send( len , f_name.name ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( debug ) printf( "ファイル名送信OK。\n" ) ;
-
- /* 受信側ファイルチェック */
- if( receive( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( buffer[0] == 0x00 ) {
- printf( "受信側でファイルのオープンに失敗しました。\n" ) ;
- if( mode == 2 ) return ;
- rs_init() ;
- exit( -1 ) ;
- }
-
- /* ファイル長送信 */
- buffer[0] = f_len / 0x1000000l ;
- buffer[1] = ( f_len & 0x00ff0000l ) / 0x10000l ;
- buffer[2] = ( f_len & 0x0000ff00l ) / 0x100l ;
- buffer[3] = f_len & 0x000000ffl ;
- if( send( 4 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( debug ) printf( "ファイル長送信OK。\n" ) ;
-
- /* ファイル日付送信 */
- buffer[0] = f_name.wr_date / 0x100 ;
- buffer[1] = f_name.wr_date ;
- if( send( 2 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( debug ) printf( "ファイル日付送信OK。\n" ) ;
-
- /* ファイル時間送信 */
- buffer[0] = f_name.wr_time / 0x100 ;
- buffer[1] = f_name.wr_time ;
- if( send( 2 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( debug ) printf( "ファイル時間送信OK。\n" ) ;
-
- /* ファイル属性送信 */
- buffer[0] = f_name.attrib ;
- if( send( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( debug ) printf( "ファイル属性送信OK。\n" ) ;
-
- /* ファイル送信 */
- printf( " %-13.13s : %10ld " , name , f_len ) ;
- loop = ( f_len + BUFFSIZE - 1l ) / BUFFSIZE ;
- for( i = 0 ; i < loop ; i++ ) putch( '.' ) ;
- for( i = 0 ; i < loop ; i++ ) {
- len = fread( buffer , 1 , BUFFSIZE , file ) ;
- if( send( len , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- /* 受信側ファイル書き込みチェック */
- if( receive( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( buffer[0] == 0x00 ) {
- printf( "送信失敗!" ) ;
- err = 1 ;
- break ;
- }
- else printf( "\b \b" ) ;
- }
- if( !( err ) ) {
- ftime( &time_2 ) ;
- speed = ( f_len_b / ( ( time_2.time - time_1.time ) * 100l
- + time_2.millitm - time_1.millitm + 1l ) + 5l ) / 10l ;
- printf( "(電送速度:約%ldkbps)" , speed ) ;
- }
-
- /* ファイルのクローズ */
- fclose( file ) ;
-
- /* 受信側ファイルチェック */
- if( receive( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( buffer[0] == 0x00 ) {
- printf( "×\n" ) ;
- }
- else printf( "○\n" ) ;
-
- /* 次のファイル展開 */
- if( ( _dos_findnext( &f_name ) ) != 0 ) {
- /* おしまい */
- buffer[0] = 0x00 ;
- if( send( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- break ;
- }
- /* つづく */
- else {
- buffer[0] = 0xff ;
- if( send( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( debug ) printf( "連続送信要求OK。\n" ) ;
- }
- }
-
- }
-
- /* 受信メイン前(^^;処理 */
- void fp_receive0()
- {
- /* ファイル送信前フラグ受信 */
- if( receive( 1 , buffer ) ) timeout() ;
- if( buffer[0] == 0x02 ) {
- if( debug ) printf( "ファイル送信前フラグ受信OK。\n" ) ;
- }
- else {
- printf( "ファイル送信前フラグが異常です、送信側コマンドを確認してください。\n" ) ;
- rs_init() ;
- exit( -1 ) ;
- }
- }
-
- /* 受信メイン処理 */
- void fp_receive()
- {
- int i , j , len , loop , err ;
- unsigned long f_len ;
- unsigned int f_time , f_date ;
- unsigned char f_attr ;
- unsigned char full_name[128] ;
- FILE *file ;
- int handle ;
- unsigned long speed , f_len_b ;
-
- /* ファイル送信フラグ受信 */
- if( receive( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( buffer[0] == 0x00 ) {
- if( debug ) printf( "ファイル送信フラグ受信OK。\n" ) ;
- }
- else {
- printf( "ファイル送信フラグが異常です、送信側コマンドを確認してください。\n" ) ;
- if( mode == 2 ) return ;
- rs_init() ;
- exit( -1 ) ;
- }
-
- /* 受信パス名長受信 */
- if( receive( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- len = *buffer ;
- if( debug ) printf( "受信パス名長受信OK。\n" ) ;
- /* 受信パス名受信 */
- if( len ) {
- if( receive( len , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( ( buffer[len-1] != '\\' ) && ( buffer[len-1] != ':' ) ) {
- buffer[len] = '\\' ;
- buffer[len+1] = 0x00 ;
- }
- else buffer[len] = 0x00 ;
- if( debug ) printf( "受信パス名受信OK。\n" ) ;
- strcpy( path , buffer ) ;
- }
- else strcpy( path , "" ) ;
-
- /* 受信ファイルチェック */
- if( receive( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( buffer[0] == 0x00 ) {
- printf( "送信側に送るファイルがありません。\n" ) ;
- if( mode == 2 ) return ;
- rs_init() ;
- exit( -1 ) ;
- }
-
- /* 受信処理ループ */
- if( mode != 2 ) printf( " ファイル名 : ファイル長\n" ) ;
- for( ; ; ) {
- ftime( &time_1 ) ;
- err = 0 ;
-
- /* 受信ファイルチェック */
- if( receive( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( buffer[0] == 0x00 ) {
- printf( "送信側でファイルのオープンに失敗しました。\n" ) ;
- if( mode == 2 ) return ;
- rs_init() ;
- exit( -1 ) ;
- }
-
- /* ファイル名長受信 */
- if( receive( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- len = *buffer ;
- if( debug ) printf( "ファイル名長受信OK。\n" ) ;
-
- /* ファイル名受信 */
- if( receive( len , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- buffer[len] = 0x00 ;
- if( debug ) printf( "ファイル名受信OK。\n" ) ;
- strcpy( name , buffer ) ;
- strcpy( full_name , path ) ;
- strcat( full_name , name ) ;
-
- /* ファイルのオープン */
- if( ( file = fopen( full_name , "wb" ) ) == NULL ) {
- printf( "受信ファイルのオープンに失敗しました(%s)。\n" , full_name ) ;
- buffer[0] = 0x00 ;
- if( send( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( mode == 2 ) return ;
- rs_init() ;
- exit( -1 ) ;
- }
-
- /* オープン OK */
- buffer[0] = 0xff ;
- if( send( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
-
- /* ファイル長受信 */
- if( receive( 4 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- f_len = (unsigned long)buffer[0] * 0x1000000l
- + (unsigned long)buffer[1] * 0x10000l
- + (unsigned long)buffer[2] * 0x100l
- + (unsigned long)buffer[3] ;
- f_len_b = f_len * 8l ;
- if( debug ) printf( "ファイル長受信OK。\n" ) ;
-
- /* ファイル日付受信 */
- if( receive( 2 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- f_date = (unsigned int)buffer[0] * 0x100
- + (unsigned int)buffer[1] ;
- if( debug ) printf( "ファイル日付受信OK。\n" ) ;
-
- /* ファイル時間受信 */
- if( receive( 2 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- f_time = (unsigned int)buffer[0] * 0x100
- + (unsigned int)buffer[1] ;
- if( debug ) printf( "ファイル時間受信OK。\n" ) ;
-
- /* ファイル属性受信 */
- if( receive( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- f_attr = buffer[0] ;
- if( debug ) printf( "ファイル属性受信OK。\n" ) ;
-
- /* ファイル受信 */
- printf( " %-13.13s : %10ld " , name , f_len ) ;
- loop = ( f_len + BUFFSIZE - 1l ) / BUFFSIZE ;
- for( i = 0 ; i < loop ; i++ ) putch( '.' ) ;
- for( i = 0 ; i < loop ; i++ ) {
- if( f_len < BUFFSIZE ) j = f_len ;
- else j = BUFFSIZE ;
- if( receive( j , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( fwrite( buffer , 1 , j , file ) < j ) {
- printf( "書き込み失敗!" ) ;
- err = 1 ;
- buffer[0] = 0x00 ;
- if( send( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- break ;
- }
- printf( "\b \b" ) ;
- f_len -= (unsigned long)j ;
- buffer[0] = 0xff ;
- if( send( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- }
- if( !( err ) ) {
- ftime( &time_2 ) ;
- speed = ( f_len_b / ( ( time_2.time - time_1.time ) * 100l
- + time_2.millitm - time_1.millitm + 1l ) + 5l ) / 10l ;
- printf( "(電送速度:約%ldkbps)" , speed ) ;
- }
-
- /* ファイルのクローズ */
- fclose( file ) ;
-
- /* ファイルの日時属性設定 */
- if( !( err ) ) {
- if( _dos_open( full_name , O_WRONLY , &handle ) != 0x00 ) {
- printf( "受信ファイルのオープンに失敗しました。" ) ;
- err = 2 ;
- }
- if( _dos_setftime( handle , f_date , f_time ) != 0x00 ) {
- printf( "受信ファイルの日時設定に失敗しました。" ) ;
- err = 3 ;
- }
- if( _dos_setfileattr( full_name , f_attr ) != 0x00 ) {
- printf( "送信ファイルの属性設定に失敗しました。" ) ;
- err = 3 ;
- }
- if( err != 2 ) _dos_close( handle ) ;
- }
-
- /* 受信 NG */
- if( err ) {
- printf( "×\n" ) ;
- unlink( full_name ) ;
- buffer[0] = 0x00 ;
- if( send( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- }
- /* 受信 OK */
- else {
- printf( "○\n" ) ;
- buffer[0] = 0xff ;
- if( send( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- }
-
- /* 次のファイルチェック */
- if( receive( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( buffer[0] == 0x00 ) break ;
- if( debug ) printf( "連続受信要求OK。\n" ) ;
-
- }
-
- }
-
- /* サーバーメイン処理 */
- void fp_server()
- {
- int len ;
- unsigned long f_len ;
- int handle ;
- FILE *file ;
-
- /* ESCが来るまで無限ループ */
- printf( " ファイル名 : ファイル長\n" ) ;
- for( ; ; ) {
- strcpy( path , "" ) ;
- while( connect_r() ) ;
-
- /* ファイル送信フラグ受信 */
- if( receive( 1 , buffer ) ) buffer[0] = 0xff ;
- switch( buffer[0] ) {
- case 0x01 : /* サーバーから送信 */
- /* 送信ファイル名長受信 */
- if( receive( 1 , buffer ) ) break ;
- len = *buffer ;
- if( debug ) printf( "送信ファイル名長受信OK。\n" ) ;
- /* 送信ファイル名受信 */
- if( receive( len , buffer ) ) break ;
- buffer[len] = 0x00 ;
- if( debug ) printf( "送信ファイル名受信OK。\n" ) ;
- strcpy( name , buffer ) ;
- fp_send() ;
- break ;
- case 0x02 : /* サーバーに受信 */
- fp_receive() ;
- break ;
- case 0x03 : /* リモートコマンド処理 */
- /* リモートコマンド長受信 */
- if( receive( 1 , buffer ) ) break ;
- len = *buffer ;
- if( debug ) printf( "リモートコマンド長受信OK。\n" ) ;
- /* リモートコマンド受信 */
- if( receive( len , command ) ) break ;
- command[len] = 0x00 ;
- if( debug ) printf( "リモートコマンド受信OK。\n" ) ;
- /* リモートコマンド実行 */
- strcat( command , ">$$fpli$$.tmp" ) ;
- system( command ) ;
- /* ファイルの長さを調べる _dos_finedではDIETしてあるデータの長さが分からない */
- strcpy( name , "$$fpli$$.tmp" ) ;
- if( ( handle = open( name , O_RDONLY|O_BINARY ) ) == EOF ) {
- f_len = 0l ;
- }
- else {
- f_len = filelength( handle ) ;
- close( handle ) ;
- }
- /* コマンド結果ファイルのオープン */
- file = fopen( name , "rb" ) ;
- /* コマンド結果ファイル長送信 */
- buffer[0] = f_len / 0x1000000l ;
- buffer[1] = ( f_len & 0x00ff0000l ) / 0x10000l ;
- buffer[2] = ( f_len & 0x0000ff00l ) / 0x100l ;
- buffer[3] = f_len & 0x000000ffl ;
- if( send( 4 , buffer ) ) break ;
- if( debug ) printf( "コマンド結果ファイル長送信OK。\n" ) ;
- /* コマンド結果ファイル送信 */
- for( ; f_len > 0l ; ) {
- len = fread( buffer , 1 , BUFFSIZE , file ) ;
- if( send( len , buffer ) ) break ;
- f_len -= (unsigned long)len ;
- }
- if( debug ) printf( "コマンド結果ファイル送信OK。\n" ) ;
- fclose( file ) ;
- unlink( name ) ;
- break ;
- default :
- printf( "ファイル送信フラグが異常です、送信側コマンドを確認してください。\n" ) ;
- break ;
- }
- if( debug ) printf( "サーバー処理1シーケンス完了\n" ) ;
- }
-
- }
-
- /* サーバーからの受信処理用(^^;ファイル名送信処理 */
- void fp_file()
- {
- int len ;
-
- /* ファイル名送信フラグ送信(^^; */
- buffer[0] = 0x01 ;
- if( send( 1 , buffer ) ) timeout() ;
- if( debug ) printf( "ファイル名送信フラグ送信OK。\n" ) ;
-
- /* 受信ファイル名長送信 */
- len = strlen( name ) ;
- *buffer = (unsigned char)len ;
- if( send( 1 , buffer ) ) timeout() ;
- if( debug ) printf( "受信ファイル名長送信OK。\n" ) ;
-
- /* 受信ファイル名送信 */
- if( send( len , name ) ) timeout() ;
- if( debug ) printf( "受信ファイル名送信OK。\n" ) ;
-
- }
-
- /* リモートコマンド処理 */
- void fp_command()
- {
- int len , i , j;
- unsigned long f_len ;
- unsigned char *c ;
-
- /* リモートコマンド送信フラグ送信(^^; */
- buffer[0] = 0x03 ;
- if( send( 1 , buffer ) ) timeout() ;
- if( debug ) printf( "リモートコマンド送信フラグ送信OK。\n" ) ;
-
- /* リモートコマンド長送信 */
- len = strlen( command ) ;
- *buffer = (unsigned char)len ;
- if( send( 1 , buffer ) ) timeout() ;
- if( debug ) printf( "リモートコマンド長送信OK。\n" ) ;
-
- /* リモートコマンド送信 */
- if( send( len , command ) ) timeout() ;
- if( debug ) printf( "受信先パス名送信OK(%s)。\n" , command ) ;
-
- /* コマンド結果長受信 */
- while( receive( 4 , buffer ) ) ;
- f_len = (unsigned long)buffer[0] * 0x1000000l
- + (unsigned long)buffer[1] * 0x10000l
- + (unsigned long)buffer[2] * 0x100l
- + (unsigned long)buffer[3] ;
- if( debug ) printf( "コマンド結果長受信OK。\n" ) ;
-
- /* コマンド結果受信&表示 */
- for( ; f_len > 0l ; ) {
- if( f_len < BUFFSIZE ) i = f_len ;
- else i = BUFFSIZE ;
- if( receive( i , buffer ) ) timeout() ;
- c = buffer ;
- for( j = 0 ; j < i ; j++ ) {
- putch( *c++ ) ;
- }
- f_len -= (unsigned long)i ;
- }
- if( debug ) printf( "コマンド結果受信OK。\n" ) ;
-
- }
-
- /* タイムアウト停止 */
- void timeout()
- {
- printf( "タイムアウトが発生しました(;_;)。\n" ) ;
- rs_init() ;
- exit( -1 ) ;
-
- }
-
- /* 割り込み処理定義 */
- void sig_out()
- {
-
- printf( "電送処理終了します。\n" ) ;
- rs_init() ;
- exit( -1 ) ;
-
- }
-
- /* タイムアウト値取得処理 */
- void timeset()
- {
- long time_0,time_1,time_2 ;
-
- time_0 = clock() ;
- time_1 = time_0 + 1l ;
- time_2 = time_0 + 2l ;
-
- while( clock() != time_1 ) ;
- for( timeout1 = 0l ; timeout1 < 2000000000l ; timeout1 += 2500l ) {
- if( clock() == time_2 ) break ;
- }
-
- if( debug ) printf( "タイムアウト値は(%ld)です。\n" , timeout1 ) ;
-
- }
-